package executor.impl;
import java.io.File;
import java.io.FileFilter;
import java.util.concurrent.ExecutorService;

public class FileCrawler implements Runnable {
	private final File folder;
	private final FileFilter fileFilter;
	private final ExecutorService fileCrawlService;
	private final ExecutorService indexExecService;
	
	public FileCrawler(File folder, FileFilter fileFilter, ExecutorService indexExecService,
			ExecutorService fileCrawlService) {
		this.folder = folder;
		this.fileFilter = fileFilter;
		this.indexExecService = indexExecService;
		this.fileCrawlService = fileCrawlService;
	}

	public void run() {
		File[] entries = folder.listFiles(fileFilter);
		if (entries != null) {
			for (File entry : entries)
				if (entry.isDirectory())
					fileCrawlService.submit(new FileCrawler(entry, fileFilter,
							indexExecService, fileCrawlService));
				else if (!alreadyIndexed(entry))
					indexExecService.submit(new IndexingTask(entry));
		}
	}
	
	
	//[rnd.nextInt(fileQueues.length)].put(entry);
	
	private boolean alreadyIndexed(File entry) {
		return false;
	}
}